<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" id="btn" value="更换颜色" />
    <!-- <button>更换颜色</button> -->
    <script>
        //1、绑定点击事件
        //2、随机生成一个RGB的颜色值
        //3、修改body标签的背景色(document.body.style.backgroundColor = 'rgb(1,1,1)')
        document.querySelector("#btn").onclick = function () {
            var r = Math.round(Math.random() * 255);
            var g = Math.round(Math.random() * 255);
            var b = Math.round(Math.random() * 255);
            // console.log(r);
            var by = document.body.style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')';
            console.log(by);
        }

    </script>
</body>

</html>